package com.w2cx.selenium.business;

import com.w2cx.selenium.base.DriverBase;
import com.w2cx.selenium.operate.MarkLibraryManageOperate;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.List;

public class MarkLibraryManageProcess {

    DriverBase driver;
    MarkLibraryManageOperate mlmh;
    public MarkLibraryManageProcess(DriverBase driver){
        this.driver = driver;
        mlmh = new MarkLibraryManageOperate(driver);
    }

    //添加标签
    public void addMark(String title){


        //点击“基础数据管理”菜单
        mlmh.clickBaseDataManageMenu();
        //点击标签库管理菜单
        mlmh.clickMarkLibraryManageMenu();



        //点击添加按钮
        mlmh.clickAddBtn();
        driver.refresh();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //输入标签名称
        mlmh.inputInformationTitle(title);
        //点击标签分类下拉框
        mlmh.clickInformationCategory();
        //选择标签分类
        mlmh.selectInformationCategory();
        //点击确定
        mlmh.clickConfirmBtn();


    }

    //判断
    public boolean addMarkSuccess(String alreadyAddMarkName){
        List<WebElement> list = mlmh.getMarkLibraryLevel0List();
        for (WebElement element:list){
            if(element.getText().contains(alreadyAddMarkName)){
                return true;
            }
        }
        return false;
    }


    //删除
    public void delMark(String alreadyAddMarkName){

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        ArrayList<WebElement> list =(ArrayList<WebElement>) mlmh.getMarkLibraryLevel0List();
        for (int i=0;i<list.size();i++){
            WebElement fatherElement = list.get(i);
            if(fatherElement.getText().contains(alreadyAddMarkName)){
                mlmh.clickDelBtn(fatherElement);
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                mlmh.clickDelOkBtn();
                return;
            }
        }
        return;
    }


    //判断删除
    public  boolean delMarkSuccess(String alreadyAddMarkName){
        //刷新
        driver.refresh();
        //
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        List<WebElement> list = mlmh.getMarkLibraryLevel0List();
        for (WebElement element:list){
            if(element.getText().contains(alreadyAddMarkName)){
                return false;
            }
        }
        return true;
    }


}
